package thread;
/** 使用匿名内部类来完成两种方式的线程创建 */
public class ThreadDemo3 extends Thread {
    public static void main(String[] args) {
        //第一种：继承thread重写run方法
        Thread t =new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                System.out.println("ff");
            }
        });
        //第二种：单独定义线程任务
        Runnable r1 = new MyRunnable11();
        Runnable r2 = new MyRunnable22();

        Thread t1 = new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                System.out.println("ff");
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0;i<1000;i++){
                System.out.println("dg");
            }
        });
        t1.start();
        t2.start();


    }
}
class MyRunnable11 implements Runnable{
    public void run(){
        for (int i = 0; i < 1000; i++) {
            System.out.println("热热热");
        }
    }
}
class MyRunnable22 implements Runnable{
    public void run(){
        for (int i = 0; i < 1000; i++) {
            System.out.println("冷冷冷");
        }
    }
}